import socket
import sys
import time

#create a udp socket
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

#bind the socket to the port
SERVERaddr = ('localhost',10000)
print('开始连接于{}主机，端口{}'.format(*SERVERaddr))
sock.connect(SERVERaddr)
message = b'this is a message.    It will be repeated.'
try:
    #发送消息
    print('发送 {!r}'.format(message))
    sock.sendto(message,SERVERaddr)
    time.sleep(1)

    print('等待回送消息')
    data,server = sock.recvfrom(4096)
    print('返回了消息：{!r}'.format(data))

finally:
    print('关闭连接（套接字）')
    sock.close()